package com.example.song.wlms.fragment;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.song.wlms.R;
import com.example.song.wlms.adapter.FragmentAdapter;
import com.example.song.wlms.homefragment.NewestFragment;
import com.example.song.wlms.homefragment.OriginalFragment;
import com.example.song.wlms.homefragment.RecommendFragment;
import com.example.song.wlms.homefragment.SpecialFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends Fragment {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<Fragment> fragmentList;
    private List<String> stringList;
    private FragmentAdapter adapter;

    public HomeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        tabLayout = (TabLayout) view.findViewById(R.id.home_tabLayout);
        viewPager = ((ViewPager) view.findViewById(R.id.home_viewPager));
        fragmentList = new ArrayList<>();
        stringList = new ArrayList<>();
        stringList.add("         推荐         ");
        stringList.add("         最新         ");
        stringList.add("         原创         ");
        stringList.add("         专题         ");
        fragmentList.add(new RecommendFragment());
        fragmentList.add(new NewestFragment());
        fragmentList.add(new OriginalFragment());
        fragmentList.add(new SpecialFragment());
        adapter = new FragmentAdapter(getChildFragmentManager(), stringList, fragmentList);
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(3);
        tabLayout.setupWithViewPager(viewPager);
    }

}
